<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/adminlte/common-js.jsp"%>
  <%@ include file="/common/adminlte/common-css.jsp"%>	
  <title>WHQ | 基础平台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/adminlte/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/adminlte/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
  		<br/>
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >机构与用户管理 / 用户管理</span>
			</li>
		</ol>
		
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              			<center>
              				<div class="btn-group">
								<button class="btn btn-info" type="button" onclick="toAddOrg();">增加机构</button>
				            	<button class="btn btn-info" type="button" onclick="alert('暂缓开通！');">增加子机构</button>
				            	<button class="btn btn-info" type="button" onclick="delOrg();">删除</button>
				            	<button class="btn btn-info" type="button" onclick="toEditOrg();">修改</button>
				            	<button class="btn btn-info" type="button" onclick="refresh();">刷新</button>
				            	<button class="btn btn-info" type="button">部门管理</button>
				            	<button class="btn btn-info" type="button">机构人员</button>
				            	<button class="btn btn-info" type="button">角色设置</button>
				            	<button class="btn btn-info" type="button">资源设置</button>	
			            	</div>					
            			</center>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            
            
            <center>
				<form id="searchFrom" class="form-horizontal">
				用户账号：<input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="userEname" id="userEname" value="" />
				用户姓名: <input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="userEname" id="userEname" value="" />
							
				<button type="button" class="btn btn-primary" onclick="getTableData();">查询</button>
				<button  type="button"
						class="btn btn-primary"
						onclick="cleanData('searchFrom');">
						重置
			    </button>
				</form>
				</center>
            
            
              <table id="example" class="table table-bordered " >
                <thead>
                <tr>
              	  <th>机构名称</th>
                  <th>机构标识</th>
                  <th>所属域</th>
                  <th>子节点数</th>
                  <th>英文全称</th>
                  <th>中文全称</th>
                  <th>当前状态</th>
                </tr>
                </thead>
                <tbody id="myList">
        
                
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
       
  <%@include file="/common/adminlte/foot.jsp" %>
  <!-- foot start -->
  <!-- right start -->
  <%@include file="/common/adminlte/right.jsp" %>
  <!-- right start -->
  

  <div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  	
	<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title">
							<font color="red">机构信息</font>&nbsp;
						</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}">
							<input type="hidden" name="orgId" id="orgId" value="">
							<input type="hidden" name="fatherId" id="fatherId" value=""/>
							<input type="hidden" name="updateCount" id="updateCount" value=""/>
							<input type="hidden" name="sysEname" id="sysEname" value=""/>
							<input type="hidden" name="subCount" id="subCount" value=""/>
							
							 <div class="box-body" id="orgFormData">
							 
			                <div class="form-group">
			                  <label for="inputOrgCname" class="col-sm-2 control-label" >机构名称</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" id="orgCname"  name="orgCname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">机构标识</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" id="orgEname"  name="orgEname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">机构代码</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" id="orgCode" name="orgCode" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">联系人</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" id="linkMan" name="linkMan" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">联系电话</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control"  id="phone" name="phone" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">所在地区</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" id="address" name="address" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">状态</label>
			                  <div class="col-sm-8">
			                    <input type="radio" checked="checked" value="1" name="orgStatus"> <i></i> 启用 
                                <input type="radio" value="0" name="orgStatus"> <i></i> 停用
			                  </div>
			                </div>
			                
			              </div>
			               <div class="box-footer">
			                <button type="button" class="btn btn-primary pull-left" onclick="cannel();">取消</button>
			                <button type="button" class="btn btn-primary pull-right" onclick="addOrg('orgForm');">提 交</button>
			              </div>
			              
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  
  
  
</body>
	<script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id=<?=rows[i].orgId?> class="closed parentNode">
					<th style="display:none;"><?=rows[i].orgId?></th>
					<td>

						<?if(rows[i].subCount>0){?>
							<a href="#" onclick="getChildTableData('<?=rows[i].orgId?>');" ><?=rows[i].orgCname?></>
						<?} else{?>		
							<?=rows[i].orgCname?>
						<?}?>		

					</td>
					<td><?=rows[i].orgEname?></td>
					<td><?=rows[i].orgDomain?></td>
					<td><?=rows[i].subCount?></td>
					<td><?=rows[i].fullEname?></td>
					<td><?=rows[i].fullCname?></td>
					<td><?=rows[i].orgStatus?></td>
				</tr>
     		<?}?>
	</script>


<script>
var id;
$(function () {
	getTableData();
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	      
	     id = $('tr.selected th').eq(0).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );

  });
  
  
//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
	cleanData('orgFormData');
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({
	    type:'post',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'json',
	    success: function(myData){
	    	console.log(myData);
			 $('#formToken').val(myData);
	  	}
	});	
}); 
  
function cleanData(id){
	$(':input','#'+id)  
	 .not(':button, :submit, :reset, :hidden,:radio')  
	 .val('')  
	 //.removeAttr('checked')  
	 .removeAttr('selected'); 
}


function getTableData(){
	//deleteAllRow();
	$.ajax({
		   type:'post',
		   url:org_search_url,
		   dataType:'json',
		   success: function(myData){
			 var rs = {};
			 rs.rows=eval(myData);
			var data = baidu.template('dataList',rs);  
			$("#myList").html(data);
			
		   }
		});	
  }
  
function getChildTableData(id){
	$.ajax({
		   type:'post',
		   url:org_search_url,
		   data:{'id':id},
		   dataType:'json',
		   success: function(myData){
			 var rs = {};
			 rs.rows=eval(myData);
			var data = baidu.template('dataList',rs);  
			    if ( $("#"+id).hasClass('opened') ) {
			    	$("#"+id).attr('class','closed parentNode');
			    	for(i = 0;i<myData.length;i++){
			    		var orgId = myData[i].orgId;
				    	$("tr[id='"+orgId+"']").remove();
			    	}
			    	//alert('del');
		        }else{
		        	$("#"+id).attr('class','opened parentNode');
		        	$("#"+id).after(data);
		          	for(i = 0;i<myData.length;i++){
			    		var orgId = myData[i].orgId;
			        	$("#"+orgId).attr('class','childNode');
			    	}
		        	//alert('add');
		        }
				
		   }
		});	
  } 
  
  
  
function toAddOrg(){
	$('#my_modal').modal('show');
}


function toEditOrg(){
	if(id=="undefined" || id =="" || id == null){
		alert("请先选中一条数据！");
		return;
	}else{
		$.ajax({
		    type:'post',
		    url:org_view_url,
		    data:{'id':id},
		    dataType:'json',
		    success: function(myData){
		    	 //console.log(myData);
				 FormUtil.fillData("#orgForm", myData,"id");
				 DictUtil.checkRadioDict("orgStatus", myData.orgStatus);
				 $('#my_modal').modal('show');

		  	}
		});	
	}
	
	
	//$('#my_modal').modal('show');
	
	
	
}

function delOrg(){
	if(id =="undefined"){
		alert("请先选中一条数据！");
		return;
	}else{
		$.ajax({
		    type:'post',
		    url:org_del_url,
		    data:{'id':id},
		    dataType:'json',
		    success: function(myData){
		    	if(myData.flag=='T'){
		    		alert("删除成功！");
		    		refresh();
		    	}

		  	}
		});	
	}

	
}

function addOrg(formId){
	
	if(!$("#" + formId)[0].checkValidity()){
		alert("请先完善必输项和必选项！");
		return ;
	}
	
	$.ajax({
	    type:'post',
	    url:org_save_url,
	    data:$("#"+formId).serialize(),
	    dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
	    	if(myData.flag=='T'){
	    		alert("添加成功！");
	    		$('#my_modal').modal('hide');
	    		refresh();
	    	}else{
	    		alert(myData.msg);
	    	}

	  	}
	});	
	
	
}

function cannel(){
	$('#my_modal').modal('hide');

}
function deleteAllRow(){
	var tb = document.getElementById('example');
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function refresh(){
    //window.location.reload();
	getTableData();
}

</script>




</html>
